mui.ready(function() {
	document.querySelector(".agreement").addEventListener("tap",function(){
				mui.openWindow({
							url: 'userAgreement.html',
						});
	})		
	var smsVerifyCode = document.querySelector(".smsVerifyCode");
	smsVerifyCode.addEventListener("tap", function() {
		var reg_phone = document.querySelector(".reg_phone").value;
		var reg1 = /(^1[3|4|5|7|8][0-9]{9}$)/;
		if (reg1.test(reg_phone) == false) {
			
			mui.toast("请输入正确的手机号码");
			
			return
		}
		smsVerifyCode.disabled = true;
		var next_time = 60;
		var time_out = setInterval(function() {
			if (next_time == 0) {
				smsVerifyCode.disabled = false;
				smsVerifyCode.innerHTML = "获取验证码";
				clearInterval(time_out);
			} else {
				next_time = next_time - 1;
				smsVerifyCode.innerHTML = next_time;
			}
		}, 1000)
		mui.ajax("/api/v1/sms/send/code", {
			data: {
				paramStr: "{mobile:" + reg_phone + ",ip:127.0.0.1,type:register}"
			},
			dataType: 'json',
			type: 'post',
			success: function(data) {
				mui.toast(data.message);
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				console.log(type);
			}
		});
	});
	//获取验证码
	document.getElementById("reg").addEventListener("tap", function() {
		var reg_phone = document.querySelector(".reg_phone").value;
		var reg1 = /(^1[3|4|5|7|8][0-9]{9}$)/;
		if (reg1.test(reg_phone) == false) {
			mui.toast("请输入正确的手机号码");
			return
		}
		var reg_password = document.querySelector(".password").value;
		var reg2 = /^[0-9A-Za-z]{6,}$/;
		if (reg2.test(reg_password) == false) {
			mui.toast("请输入6位以上密码");
			return
		}
		var re_password = document.querySelector(".re_password").value;
		if (re_password != reg_password) {
			mui.toast("确认密码错误");
			return
		}
		var temp = document.getElementsByName("sex");
		for (var i = 0; i < temp.length; i++) {
			if (temp[i].checked) {
				var sex = temp[i].value;
			}
		}
		if (sex == undefined) {
			
			mui.toast("请选择账户类型");
		
			return
		}

		
		var pname = document.querySelector(".pname").value;
		var input_phone_message = document.querySelector("#input_phone_message").value;
		mui.ajax("/api/v1/user/register", {
			data: {
				paramStr: "{userName:" + reg_phone + ",password:" + reg_password + ",mobile:" + reg_phone + ",pMobile:'" + pname + "',smsVerifyCode:" + input_phone_message + ",sex:" + sex + "}"
			},
			dataType: 'json',
			type: 'post',
			success: function(data) {
			
				mui.toast(data.message);
				if (data.code == 200) {
					setTimeout(function() {
					
						mui.openWindow({
							url: 'login.html',
						});
					}, 3000)
				}

			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				alert("未知错误");
			}
		});
	});
})